package jym.tan.movielibrary.component.ui.table.model;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import jym.tan.movielibrary.constant.ComponentConstant;
import jym.tan.movielibrary.model.MovieSearchModel;

public class MovieSearchResultTableModel extends AbstractTableModel {

	private static final long serialVersionUID = 46L;

	private List<MovieSearchModel> movieSearchModels;
	private ComponentConstant.ColumnName[] columns = ComponentConstant.Column.MOVIE_SEARCH_RESULT_TABLE;
	
	public int getRowCount() {
		return movieSearchModels.size();
	}

	public int getColumnCount() {
		return columns.length;
	}
	
	@Override
	public String getColumnName(int columnIndex) {
		return columns[columnIndex].getName();
	}

	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return columns[columnIndex].getClass();
	}
	
	public Object getValueAt(int rowIndex, int columnIndex) {
		Object returnValue = new Object();
		switch(columnIndex) {
			case 0: 
				returnValue = movieSearchModels.get(rowIndex).getName();
				break;
			case 1: 
				returnValue = movieSearchModels.get(rowIndex).getReleased();
				break;
			case 2: 
				returnValue = movieSearchModels.get(rowIndex).getLanguage();
				break;
			case 3: 
				returnValue = movieSearchModels.get(rowIndex).getRating();
				break;
			case 4: 
				returnValue = movieSearchModels.get(rowIndex).getCertification();
				break;
			case 5: 
				returnValue = movieSearchModels.get(rowIndex).getImdb_id();
				break;
		}		
		return returnValue;
	}

	public List<MovieSearchModel> getMovieSearchModels() {
		return movieSearchModels;
	}

	public void setMovieSearchModels(List<MovieSearchModel> movieSearchModels) {
		this.movieSearchModels = movieSearchModels;
	}
}
